<!DOCTYPE html>

<html>
<head>
{{template "common/head.html" .}}
    <style type="text/css">

    </style>

</head>

<body class="layui-layout-body">
<div id="app">
    <div class="layui-layout layui-layout-admin">
    {{template "common/adminMenu.html" .}}

        <div class="layui-body">
            <table class="layui-table">
                <colgroup>
                    <col width="150">
                    <col width="150">
                    <col width="200">
                    <col>
                </colgroup>
                <thead>
                <tr>
                    <th>缩略图</th>
                    <th>标题</th>
                    <th>上传时间</th>
                    <th>拍摄时间</th>
                    <th>拍摄地址</th>
                    <th>是否公开</th>
                    <th>操作</th>
                </tr>
                </thead>
                <tbody>
                {{range .data}}
                <tr>
                    <td>
                        {{if eq .Type 0}}
                            <img src="{{$.oss_url}}{{.Url}}?x-oss-process=image/resize,m_fill,h_100,w_100,limit_0" width="100" />
                         {{else}}
                            <img src="{{.Url | getVideoUrl}}?x-oss-process=image/resize,m_fill,h_100,w_100,limit_0" width="100" />
                        {{end}}
                    </td>
                    <td>{{.Title}}</td>
                    <td>{{date .CreateTime "Y-m-d H:i:s"}}</td>
                    <td>{{.ShootTime}}</td>
                    <td>{{.Address}}</td>
                    <td>
                        {{if eq .IsShow 0}}
                            公开
                        {{else}}
                            私有
                        {{end}}
                    </td>
                    <td>
                        <button class="layui-btn layui-btn-normal layui-btn-sm" onclick="location.href='/admin/product/upload?id={{.Id}}'"><i class="layui-icon layui-icon-edit"></i></button>
                        <button class="layui-btn layui-btn-danger layui-btn-sm" onclick="delProduct({{.Id}})"><i class="layui-icon layui-icon-delete"></i></button>
                    </td>
                </tr>
                {{end}}
                </tbody>
            </table>
        </div>

    {{template "common/adminFooter.html" .}}
    </div>
</div>
</body>

<script>
    var data = {{ .data }};
    window.onload = function () {
        var m = document.getElementById("menu-product");
        var s = document.getElementById("menu-product-index");
        m.parentElement.className = m.parentElement.className + " layui-nav-itemed";
        m.className = m.className + " menu-active";
        s.className = m.className + " layui-this";
    }
    new Vue({
        el: '#app',
        data: {
            theme: 'ligth'
        },
        mounted(){
            layui.use('element', function(){
                element = layui.element;
                element.render('nav');
            });
        },
        methods: {

        }

    })
    var delModal = "";
    var test = "";
    function delProduct(id){
        console.log(id);
        delModal = layer.open({
            type: 1
            ,title: "提示信息" //不显示标题栏
            ,closeBtn: false
            ,area: '300px;'
            ,shade: 0.8
            ,id: 'LAY_layuipro' //设定一个id，防止重复弹出
            // ,btn: ['删除', '取消']
            ,btnAlign: 'c'
            ,moveType: 1 //拖拽模式，0或者1
            ,content: '<div style="text-align: center;padding: 20px;"><p>确认删除？</p>' +
                    '<br><button class="layui-btn layui-btn-primary" onclick="layer.close(delModal)">取消</button>\n' +
                    '    <button class="layui-btn layui-btn-danger" onclick="doDel('+id+')">删除</button></div>'
            ,success: function(layero){

            }
        });
    }
    function doDel(id) {
        layer.close(delModal)
        axios.post("/admin/product/delProduct", {
            'id': id
        })
        .then(function (response) {
            if (response.data.code === 1) {
                location.reload()
            } else {
                showMsg(response.data.info)
            }
        })
    }
</script>
</html>
